import { defineStore } from 'pinia'

// 定义store
export const useCounterStore = defineStore('counter', {
  // 状态
  state: () => ({
    count: 0,
    name: 'Counter'
  }),
  // getters
  getters: {
    doubleCount: (state) => state.count * 2,
    getCountWithName() {
      return `${this.name}: ${this.count}`
    }
  },
  // 动作
  actions: {
    increment() {
      this.count++
    },
    decrement() {
      this.count--
    },
    reset() {
      this.count = 0
    },
    setName(name) {
      this.name = name
    }
  }
})